import { MenuItemDefinition, FeatureManager } from '@amcax/base';
import { PRODUCT_EVENT } from '@app-cad/common/Constants';
import { userEvents } from '@app-cad/module';
import { ProductTreeNode } from '../../types';

export const resort: MenuItemDefinition<ProductTreeNode> = {
  id: 'resort',
  children: '重新排序',
  hidden: ({ props: { parent, type } }) =>
    !!parent && // root node has no parent
    (!FeatureManager.isFeatureEnabled('assemble-part-resort') ||
      !['part', 'product'].includes(type)),
  onClick: ({ props: node }) =>
    userEvents.emit(PRODUCT_EVENT.PENDING_RESORT_DOC, node),
};
